#import cv2
import  matplotlib.pyplot as plt
import numpy as np
from PIL import Image
import sys
import os

def xcombine(img1, img2, newname):
    #cutimage="p2png.png"
    if os.path.exists(img1):
        img1 = Image.open(img1)
        flag1 = 1
    else:
        flag1 = 2
    #img1 = img.convert('L')
    if os.path.exists(img2):
        img2 = Image.open(img2)
        flag2 = 1
    else:
        flag2 = 2

    #print(img.shape)
    if flag1 == 1 and flag2 == 1:
        plt.subplot(211)
        plt.imshow(img1)
        plt.subplot(212)
        plt.imshow(img2)
        plt.savefig(fname=newname, format='png', dpi=100)
        #plt.show()
    else:
        print("no ps1 or cutimage")




if __name__ == "__main__":
    #img = "G171013_C05906_0696.fit"
    # img1 = "a1.png"
    # img2 = "a2.png"
    # newname = "new.png"
    img1 = str(sys.argv[1])
    img2 = str(sys.argv[2])
    newname = str(sys.argv[3])
    xcombine(img1, img2, newname)


